"""trade URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

from system import issue, robot
from . import common, task
from account import member, fund, trade, order, kline
from shop import goods

urlpatterns = [
    path('admin/', admin.site.urls),
    path('ts', common.timestamp),
    path('ping', common.ping),
    path('test', common.test),
    path('test_get_order', common.test_get_order),
    path('sign_in', member.sign_in),
    path('sign_up', member.sign_up),
    path('recharge', fund.recharge),  # 充值
    path('withdraw', fund.withdraw),  # 提现

    # 账号
    path('member_orders', order.my_order_list),  # 会员订单列表
    path('member_fund', fund.get_member_fund),
    path('my_goods_list', member.my_goods_list),

    # 交易
    path('buy', trade.buy),  # 买入
    path('sell', trade.sell),  # 卖出
    path('deal', trade.deal),  # 成交回调
    path('notify_has_order', trade.notify_has_order),  # 成交回调
    path('cancel_order', trade.cancel_order),  # 取消订单
    path('notify', trade.notify),  # 给撮合引擎用的通知接口

    # 商品
    path('goods_list', goods.goods_list),
    path('goods_detail', goods.goods_detail),
    path('add_goods', goods.add_goods),
    path('update_goods', goods.update_goods),
    path('del_goods', goods.del_goods),

    # 系统
    path('create_goods', issue.create_goods),
    path('batch_allocate_goods', issue.batch_allocate_goods),
    path('auto_trade', robot.auto_trade),
    path('airdrops', issue.airdrops),

    # K线
    path('getKline', kline.getKline),
]
from apscheduler.schedulers.background import BackgroundScheduler

scheduler = BackgroundScheduler()
# # 1分钟
scheduler.add_job(task.tick, 'interval', seconds=60)
# # 1小时
scheduler.add_job(task.tick60min, 'interval', seconds=60*60)
# # 1天
scheduler.add_job(task.tick60min, 'interval', seconds=60*60*12)

# ---------- 测试 ------------
# 1分钟
# scheduler.add_job(task.tick, 'interval', seconds=5)
# # 1小时
# scheduler.add_job(task.tick60min, 'interval', seconds=10)
# # 1天
# scheduler.add_job(task.tick1day, 'interval', seconds=15)
# ---------- 测试 end ------------
scheduler.add_job(robot.exec_auto_trade, 'interval', seconds=60)
scheduler.start()
